//
//  QSTextField.swift
//  chat
//
//  Created by 1 on 2023/3/28.
//

import SwiftUI

struct QSTextField: View {
    var placeholder: String
    @Binding var text: String
    var editingChanged: (Bool)->() = { _ in }
    var commit: ()->() = { }
    var keyboardType:UIKeyboardType = .default
    var fontSize: CGFloat = 16

    var body: some View {
        ZStack(alignment: .leading) {
            if text.isEmpty {
                Text(placeholder)
                    .foregroundColor(MBAColor.com_placehoder.color)
                    .font(.system(size: fontSize))
            }
            TextField("", text: $text, onEditingChanged: editingChanged, onCommit: commit)
                .keyboardType(keyboardType)
                .foregroundColor(MBAColor.com_white.color)
                .font(.system(size: fontSize))
        }
    }
}


struct QSTextField_Previews: PreviewProvider {
    static var previews: some View {
        QSTextField(placeholder: "提示", text: .constant("33"))
            .background(.yellow)
    }
}
